package aos.ydksxt.service.cxfxtj;

import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;
import aos.framework.core.utils.AOSUtils;
import aos.framework.web.router.HttpModel;
import aos.ydksxt.service.common.CommonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 国土信息查询服务
 * Created by stiofan on 2017/2/2.
 */
@Service
public class GtxxcxfxService extends CommonService {
    @Override
    @Transactional
    public void initView(HttpModel httpModel) {
        httpModel.setViewPath("ydksxt/cxfxtj/gtxxcxfx.jsp");
    }
    @Transactional
    public void queryGtdrxxByParams(HttpModel httpModel) {
        String querySql = "select gt.tdzdh,\n" +
                "       gt.tdsyqr,\n" +
                "       gt.tdmj,\n" +
                "       gt.tdxz,\n" +
                "       gt.tdyt,\n" +
                "       gt.tdyz,\n" +
                "       gt.tdzldz,\n" +
                "       gt.tdsyq_qsrq,\n" +
                "       gt.tdsyq_zzrq,\n" +
                "       gt.tdsyq_zsbh,\n" +
                "       gt.sjcjrq_qsrq,\n" +
                "       gt.sjcjrq_zzrq,\n" +
                "       gt.tdsyqlxmc\n" +
                "  from ydks.dj_wbdr_gtxx gt\n" +
                " where gt.yxbz = 'Y'\n" ;
        Dto inDto = httpModel.getInDto();
        Dto params = Dtos.newDto();
        if (StringUtils.isNotEmpty(inDto.getString("tdzdh"))) {
            params.put("tdzdh", inDto.getString("tdzdh"));
            querySql += "   and gt.tdzdh = :tdzdh\n" ;
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdsyqr"))) {
            params.put("tdsyqr", inDto.getString("tdsyqr"));
            querySql += "   and gt.tdsyqr = :tdsyqr\n";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdsyqZsbh"))) {
            params.put("tdsyqZsbh", inDto.getString("tdsyqZsbh"));
            querySql += "   and gt.tdsyq_zsbh = :tdsyqZsbh";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdsyqqsrq"))) {
            params.put("tdsyqqsrq", inDto.getDate("tdsyqqsrq"));
            querySql += "   and gt.tdsyq_qsrq >= :tdsyqqsrq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdsyqzzrq"))) {
            params.put("tdsyqzzrq", inDto.getDate("tdsyqzzrq"));
            querySql += "   and gt.tdsyq_zzrq <= :tdsyqzzrq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("sjcjrqqsrq"))) {
            params.put("sjcjrqqsrq", inDto.getDate("sjcjrqqsrq"));
            querySql += "   and gt.sjcjrq_qsrq >= :sjcjrqqsrq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("sjcjrqzzrq"))) {
            params.put("sjcjrqzzrq", inDto.getDate("sjcjrqzzrq"));
            querySql += "   and gt.sjcjrq_zzrq <= :sjcjrqzzrq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdmjq"))) {
            params.put("tdmjq", inDto.getString("tdmjq"));
            querySql += "   and gt.tdmj >= :tdmjq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdmjz"))) {
            params.put("tdmjz", inDto.getString("tdmjz"));
            querySql += "   and gt.tdmj <= :tdmjz";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdxz"))) {
        params.put("tdxz", inDto.getString("tdxz"));
        querySql += "   and gt.tdxz = :tdxz";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdyt"))) {
        params.put("tdyt", inDto.getString("tdyt"));
        querySql += "   and gt.tdyt = :tdyt";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdyzq"))) {
            params.put("tdyzq", inDto.getString("tdyzq"));
            querySql += "   and gt.tdyz >= :tdyzq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("tdyzz"))) {
            params.put("tdyzz", inDto.getString("tdyzz"));
            querySql += "   and gt.tdyz <= :tdyzz";
        }
        
//        if (StringUtils.isNotEmpty(inDto.getString("ssglyDm"))) {
//            params.put("ssglyDm", inDto.getString("ssglyDm"));
//            querySql += "   and gt.lrr_dm = :ssglyDm";
//        }
//		if (StringUtils.isNotEmpty(inDto.getString("tdbh"))) {
//			params.put("tdbh", inDto.getString("tdbh"));
//			querySql += "   and gt.lrr_dm = :tdbh";
//		}
        List results = persistenceDAO.findAllBySql(querySql, params);
        httpModel.setOutMsg(AOSJson.toGridJson(AOSUtils.list2Map(results)));
    }
}
